package com.gapp.king.web.server;

import com.gapp.king.web.client.LoginInfo;
import com.gapp.king.web.client.LoginService;
import com.google.appengine.api.users.User;
import com.google.appengine.api.users.UserService;
import com.google.appengine.api.users.UserServiceFactory;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

public class LoginServiceImpl extends RemoteServiceServlet implements
		LoginService {

	@Override
	public LoginInfo login(String requestUri) {
		// TODO Auto-generated method stub
		
		UserService userService = UserServiceFactory.getUserService();
		User user = userService.getCurrentUser();
		LoginInfo logininfo = new LoginInfo();
		
		if( user != null)
		{
			logininfo.setLoggedIn(true);
			logininfo.setEmailAddress(user.getEmail());
			logininfo.setNickName(user.getNickname());
			logininfo.setLogoutURL(userService.createLogoutURL(requestUri));
		}
		else
		{
			logininfo.setLoggedIn(false);
			logininfo.setLoginURL(userService.createLoginURL(requestUri));
		}
		
		return logininfo;
	}

}
